/**
 * https://leetcode-cn.com/problems/valid-parentheses/
 */
 var isValid = function(s) {
    const validMap = {
        "}": "{",
        "]": "[",
        ")": "(",
    };
    // const stack = new Stack();
    const stack = [];
    const arr = s.split('');
    let result = true;
    try {
        arr.forEach((char) => {
            if (!validMap[char]) {
                stack.unshift(char);
            } else {
                if (stack[0] === validMap[char]) {
                    stack.shift();
                } else {
                    throw 'invalid';
                }
            }
        });
        if (stack.length) {
            result = false;
        }
    } catch (e) {
        result = false;
    }
    return result;
};
